class ScorePanel {
  score: number
  level: number
  readonly maxLevel: number = 10
  scoreElem: HTMLElement
  levelElem: HTMLElement
  constructor() {
    this.score = 0
    this.level = 1
    this.scoreElem = document.getElementById('score') as HTMLElement
    this.levelElem = document.getElementById('level') as HTMLElement
  }

  // 对分数计数进行封装
  addScore() {
    this.score++
    this.scoreElem.innerText = String(this.score)
    // 升级，每5分升1级
    if (this.score % 5 === 0) {
      this.levelUp()
    }
  }

  // 等级提升
  levelUp() {
    if (this.level >= this.maxLevel) {
      return
    }
    this.level++
    this.levelElem.innerText = String(this.level)
  }
}

export default ScorePanel